{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import holoviews as hv\n",
    "import geoviews as gv\n",
    "import geoviews.feature as gf\n",
    "\n",
    "from cartopy import crs\n",
    "from geoviews import opts\n",
    "\n",
    "gv.extension('bokeh')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sample_data(shape=(73, 145)):\n",
    "    \"\"\"Returns ``lons``, ``lats`` and ``data`` of some fake data.\"\"\"\n",
    "    nlats, nlons = shape\n",
    "    ys = np.linspace(-np.pi / 2, np.pi / 2, nlats)\n",
    "    xs = np.linspace(0, 2*np.pi, nlons)\n",
    "    lons, lats = np.meshgrid(xs, ys)\n",
    "    wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)\n",
    "    mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)\n",
    "\n",
    "    lats = np.rad2deg(ys)\n",
    "    lons = np.rad2deg(xs)\n",
    "    data = wave + mean\n",
    "\n",
    "    return lons, lats, data\n",
    "\n",
    "lons, lats, data = sample_data()\n",
    "\n",
    "# Make sure we declare the central longitude\n",
    "contours = gv.FilledContours((lons, lats, data), crs=crs.PlateCarree(central_longitude=180))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(contours * gf.coastline).opts(\n",
    "    opts.FilledContours(levels=8, color_levels=10, cmap='nipy_spectral', colorbar=True, width=600, height=300, projection=crs.Mollweide()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
